package com.yayan.xh.service;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yayan.xh.bean.NewsBean;
import com.yayan.xh.dao.INewsDao;
import com.yayan.xh.dao.NewsDao;

@Service
public class NewsService implements INewsService {
	
	private INewsDao newsDao;
	
	public NewsService() {
		newsDao = new NewsDao();
	}

	@Override
	public Integer getNewsPageCount(Map<String, String> map) {
		Integer count = 0;
		try {
			count = newsDao.getNewsPageCount(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}

	@Override
	public List<Map<String, Object>> getNewsPage(Map<String, String> map) {
		List<Map<String, Object>> result = null;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				if(null != map.get("newsId")) {
					result = newsDao.getNewsByNewsId(map);
				} else {
					result = newsDao.getNewsPage(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<NewsBean> getNewsBack(Map<String, String> map) {
		List<NewsBean> result = null;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				result = newsDao.getNewsListBack(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public boolean saveNews(Map<String, String> map) {
		boolean f = false;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				f = newsDao.saveNews(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return f;
	}

	@Override
	public NewsBean getNewsByIdBack(Map<String, String> map) {
		NewsBean result = null;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))
					&& null != map.get("newsId") && !"0".equalsIgnoreCase(map.get("newsId"))) {
				result = newsDao.getNewsByIdBack(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public boolean modifyNews(Map<String, String> map) {
		boolean f = false;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				f = newsDao.modifyNews(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return f;
	}

	@Override
	public boolean delNews(Map<String, String> map) {
		boolean f = false;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))
					&& null != map.get("newsId") && !"0".equalsIgnoreCase(map.get("newsId"))) {
				f = newsDao.delNews(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return f;
	}

}
